package com.example.myerp.service.serviceimpl;

import com.example.myerp.pojo.*;
import com.example.myerp.service.DesignService;
import com.example.myerp.service.MoudleService;
import com.example.myerp.service.MyFeignPurchaseService;
import com.example.myerp.service.PurchaseService;
import com.example.myerp.until.RedisUtil;
//import io.seata.spring.annotation.GlobalTransactional;


import com.mycloud.api.pojo.ApiGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyFeignPurchaseServiceImpl implements MyFeignPurchaseService {

    @Autowired
    DesignService designService;

    @Autowired
    PurchaseService purchaservice;

    @Autowired
    RedisUtil redisUtil;


    @Autowired
    MoudleService moudleService;

    //@GlobalTransactional(name = "fxp_product_one_Add_group", rollbackFor = Exception.class)
    @Override
    public Integer product_one_Add(String proName) {
        Integer rowen = 0;
        try {
            ProclassOne one = new ProclassOne();
            one.setProName(proName);
            Integer gid = designService.getInsertOneCslassifyByProName(proName);
            purchaservice.Product_one_Add(gid + "", one.getProName());
            rowen = 1;
        } catch (Exception e) {
            e.printStackTrace();
            rowen = 0;
        }
        return rowen;
    }

    @Override
    public Integer product_sencond_Add(String preName, Integer iId) {
        ProcalssTwo two = new ProcalssTwo();
        two.setiId(iId);
        two.setProName(preName);
        Integer sencond_Id = designService.getInsertProcalssTwoByProName(two);
        Integer integer = purchaservice.product_second_Add(iId + "", sencond_Id + "", preName);
        return integer;
    }

    @Override
    public PageMyself<MakeHouse> makeHousePagefindByPager(Integer pageSize, Integer pageNum) {

        PageMyself<MakeHouse> housePageMyself = null;
        if (redisUtil.hasKey("makeHouse" + pageNum.toString() + pageSize.toString())) {
            housePageMyself = (PageMyself<MakeHouse>) redisUtil.get("makeHouse" + pageNum.toString() + pageSize.toString());
        } else {
            housePageMyself = designService.makeHousePagefindByPager(pageSize, pageNum);
            redisUtil.set("makeHouse" + pageNum.toString() + pageSize.toString(), housePageMyself);
        }


        return housePageMyself;
    }

    @Override
    public Integer product_three_Add(String proName, Integer iId, Integer iiId) {
        ProclassThree three = new ProclassThree(null, proName, iId, iiId);
        Integer threeId = designService.getInsertProclassThreeByProName(three);
        Integer integer = purchaservice.product_three_Add(threeId + "", proName, iiId + "");
        return integer;
    }

    @Override
    public void updateInfoRepby(Integer product_id) {
        designService.updateInfoRepby(product_id);
    }

    @Override
    public PageMyself<ApiGoods> goodsfindByPager(Integer pageNum, Integer pageSize) {

        PageMyself<ApiGoods> page = designService.goodsfindByPager(pageNum, pageSize);
//
        return page;
    }

    @Override
    public PageMyself<ApiGoods> goodsfindByPagers(Integer pageNum, Integer pageSize) {
        PageMyself<ApiGoods> page = designService.goodsfindByPagers(pageNum, pageSize);
        return page;
    }

    @Override
    public List<ApiGoods> fanGoods(Long fileId) {
        List<Integer> productId = moudleService.selproId(fileId);
        List<ApiGoods> apiGoods = designService.fanGoods(productId);
        return apiGoods;
    }
}
